window.onload = function(){
	var nun = 0;
	function Run () {
		// 捕捉到元素
		var a = document.getElementsByClassName('banner_tp');
		var b = document.getElementsByClassName('banner_d');
		// 循环让li消失
		for (var i = 0; i < a.length; i++) {
			a[i].style.display='none';
			b[i].style.backgroundColor='#818181';
		};
		//只出现当前的那一个
		a[nun].style.display='block';
		b[nun].style.backgroundColor="#fff";
		// nun++;
		// 走到最后一个，需要判断让他重新来过
		if (nun==a.length-1) {
			nun = 0;
		} else{
			nun++;
		};
	}

	// var time = setInterval(Run, 1000);

	var time = setInterval(Run, 2000);
	var banner_a = document.getElementsByClassName('banner_a');
	// 鼠标进来的事件
	banner_a[0].onmouseover = function(){
		clearInterval(time);
	}
	// 鼠标出去的事件
	banner_a[0].onmouseleave = function(){
		time = setInterval(Run, 1000);
	}

	var banner_d = document.getElementsByClassName('banner_d');
	for (var i = 0; i < banner_d.length; i++) {
		click_change(i);
	};
	function click_change (i) {
		banner_d[i].onclick = function () {
			nun = i;
			Run();
		}
	}
	// 左右按钮
	var banner_t = document.getElementsByClassName('banner_t');
	var banner_p = document.getElementsByClassName('banner_p');
	banner_t[0].onclick = function () {
		if ((nun-1)==0) {
			nun=4;
		} else if(nun==0){
			nun=3;
		}
		else{
			nun=nun-2
		};
		Run();
	}
	banner_p[0].onclick = function () {
		Run();
	}
	var slift_of = document.getElementsByClassName('lift_of');
	var lift_tc = document.getElementsByClassName('lift_tc');
	// 鼠标进来的事件
	slift_of[0].onmouseover = function(){
		lift_tc[0].style.display='block';
	}
	// 鼠标出去的事件
	slift_of[0].onmouseleave = function(){
		lift_tc[0].style.display='none';
	}
}

